<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/index.css">
    <link rel="stylesheet" type="text/css" href="../css/data-flex.min.css">
</head>
<body>
    <div id="templateContent"></div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/service/service-tool.js"></script>
<script type="text/javascript" src="../script/service/service-app.js"></script>
<script type="text/javascript" src="../script/service/service-user.js"></script>
<script type="text/javascript" src="../script/service/service-logic.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S;
    var templateNo, templateType;
    var pageNo = 1, pageSize = 10, pageParam;
    apiready = function(){
        $S = SERVICE();
        USER = USER();
        pageParam = api.pageParam;
        console.log(JSON.stringify(pageParam) + '=====pageParam');
        templateNo = pageParam.templateNo;
        templateType = pageParam.templateType;
        
        fnInit();
    };
    // 初始化
    function fnInit() {
        if(templateType == 'list') {
            load();
        }else {
            getPageData();
        }
        
    }

    function load() {
        fnGetSubList('load');
        fnAddHeaderRefreshingEvent(function() { //设置下拉刷新
            fnGetSubList('headerRefreshing');
        });

        fnAddFooterLoadingEvent(function() { // 设置上拉加载
            fnGetSubList('load');
        });

    }

    // 获取页面数据
    function getPageData(sign) {
        var url = 'jsHtml/findListCode';
        var params = {
            "codeNum":"002",
            "entityName": "messageInfo" 
        };
        if(templateType == 'list') {
            if(sign == 'headerRefreshing') {
                pageNo = 1;
            }else {
                pageNo ++;
            }
            params.pageNo = pageNo;
            params.pageSize = pageSize;
        }
        
        var callback = function(data) {
            // status 为200时,只返回data
            var html = data.htmlCodeFragment, js = data.jsCodeFragment, css = data.cssCodeFragment;
            insertCss(css);
            insertJs(js);
            $('#templateContent').append(html);
            // status 不是200时,全部返回
            api.refreshHeaderLoadDone();
            try {
                // 渲染完成执行的方法，放到后台录入的
                // 每次请求完成都会执行
                domAlreadyInsert();
            }catch(e) {

            }
        };
        var error = function(res) {
            // status 不是200时,全部返回
            api.refreshHeaderLoadDone();
        };
        POST(url, params, callback, error);
    }

    function insertCss(css) {
        var style = document.createElement('style');
        style.type = 'text/css';
        style.innerText = css;
        document.head.append(style);
    }

    function insertJs(js) {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.innerText = js;
        document.body.append(script);
    }
</script>
</html>